#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

int main() {
    int N = 0;
    scanf("%d", &N);
    getchar();

    char ch[26];
    int num[26];

    for (int i = 0; i < N; i++) {
        scanf("%c", &ch[i]);
        scanf("%d", &num[i]);
        getchar();
    }

    char password[31];
    scanf("%s", password);

    int sum = 0;
    int len = strlen(password);

    for (int i = 0; i < len; i++) {
        for (int j = 0; j < N; j++) {
            if (password[i] == ch[j]) {
                sum += num[j];
                break;
            }
        }
    }

    printf("%d", sum);
    return 0;
}
